<?php
/*
	Muffinz CMS - A website content management system.
	Copyright (C) 2010-2011 Sigitas Zelenkovas

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
	
	Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/

$s[] = microtime(); 
require_once("core.php");

if(isset($_GET['page'])){
	if(strstr($_GET['page'], "/")){
		$buffer = $_GET['page'];
		$_GET['page'] = rstrstr($_GET['page'], "/");
		$_GET['pd1'] = substr(strstr($buffer, "/"), 1);
	}
	
	if(file_exists("includes/modules/".str_replace("../", "", $_GET['page']).".module.php")){
		$module = str_replace("../", "", $_GET['page']).".module.php";
	}else {
		unset($_GET['pd1']);
		$module = "news.module.php";
		$cTheme->AddModuleError("<b>Error 404</b>, page was not found. If website linked to this page, there is something wrong.
			Please contact website administrator and solve this issues once and for all. <br />
				<li><b>Missing page: &nbsp;".htmlentities($_GET['page'])."</b></li>
				<li><b>Referer: &nbsp;".(($_SERVER['HTTP_REFERER'] != null) ? $_SERVER['HTTP_REFERER'] : "[none]")."</b></li>
			<br />Website automaticly loaded main page below.");
	}
}else {
	$module = "news.module.php";
}


require_once("includes/modules/$module");

$cTheme->Theme("main")or die($cTheme->Error(__LINE__));

$cTheme->SetPanels()or die($cTheme->Error(__LINE__));
$cTheme->SetMenu()or die($cTheme->Error(__LINE__));
$cTheme->SetModules()or die($cTheme->Error(__LINE__));

$cTheme->TitleBase($_SESSION['sys']['title_base']);

//$cTheme->AddHeader("<link rel=\"image_src\" href=\"http://88.118.32.126/images/logo.png\" />");

$s[] = microtime();
$cTheme->SetParam("subfooter", "Script generation time: ".($s[1] - $s[0])." || And with ".($q->Count())." mysql query(ies)")or die($cTheme->Error(__LINE__));
$cTheme->SetParam("footer", "Footer data")or die($cTheme->Error(__LINE__));

$cTheme->ParseTemplate()or die($cTheme->Error(__LINE__));